public class EqualSubstring {

    public int equalSubstring(String s, String t, int maxCost) {
        int count = 0;
        int l = 0;
        char[] chars1 = s.toCharArray();
        char[] chars2 = t.toCharArray();
        for (int i = 0; i < s.length(); i++) {
            count += Math.abs(chars1[i] - chars2[i]);
            if (count > maxCost) {
                count -= Math.abs(chars1[l] - chars2[l]);
                ++l;
            }
        }
        return s.length() - l;
    }
}
